home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5098 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: news2.ios.com!usenet
  2. From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using MFC with C
  5. Date: Fri, 02 Feb 1996 14:49:16 GMT
  6. Organization: Internet Online Services
  7. Message-ID: <4et7o1$1ur@news2.ios.com>
  8. References: <4ek2gh$t26@news1.usa.pipeline.com>
  9. NNTP-Posting-Host: ppp-38.ts-7.hck.idt.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. grantp@usa.pipeline.com(Pete) wrote:
  13. >There's no (reasonable) way to call C++ class member functions  
  14. >directly from C.  You need to write an API layer for the C++ module. 
  15. >If you're passing pointers to C++ classes to the C side, then you can 
  16. >do something like this: 
  17. >int FooApi (void * object, int arg) 
  18. > { 
  19. >   FooClass * p = (FooClass*)object; 
  20. >   return p->Foo(arg); 
  21. > } 
  22. >Of course, the two lines can be combined; I just thought it might 
  23. >be clearer when split into two. 
  24. >> 
  25.  
  26. There could be also another possiblity:
  27.  
  28. Take the C code, and if necessary declare all C functions as extern
  29. "C" in the header. Include C++ header for objects you want to call and
  30. compile everything as a C++. Then you are able to call C++ member
  31. functions from within C functions. Though overloaded functions will
  32. not compile.
  33. *******************************************
  34. *    Vlastimil Adamovsky                  *
  35. * Smalltalk, C++ and Envelop development  *
  36. *******************************************
  37.  
  38.